<template>
<view>
<view class="logo">
    <image mode="scaleToFill" src="/static/images/login_logo.png"></image>
</view>
<view class="input_sec flex">
    <view>账号</view>
    <input @input="inputIdCard" maxlength="18" placeholder="请输入手机号或证件号码" type="text">
</view>
<view class="input_sec flex">
    <view>密码</view>
    <input password @input="inputPwd" placeholder="请输入账号密码" type="text">
</view>
<view @tap="toPwd" class="especial">忘记密码</view>
<view @tap="loginEvent" class="btn theme_btn">登录</view>
<view @tap="toReg" class="btn default_btn">我要注册</view>
<view @tap="makePhoneCall" class="call">客服热线：400-0035-125</view>
</view>
</template>

<script>
	import {login,loginInfoByShareToken} from '@/api/loginManage'
	import Vue from 'vue'
	import { ACCESS_TOKEN } from '@/store/mutation-types'
var t = require("../../utils/request.js"),
    e = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../utils/api.js")),
    a = require("../../utils/util.js"),
    n = e.default.userLogin,
    o = e.default.loginByToken,
    i = e.default.userBind,
    app = getApp(),
    r = /^1([3-9])\d{9}$/,
    d = /^[0-9]*$/;

export default {
  data() {
    return {
      idcard: "",
      password: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (t) {},
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {
    return {
      title: "让公益更生活 让生活更公益",
      path: "/pages/index/index",
      imageUrl: "/static/images/zyh_logo.jpg"
    };
  },
  methods: {
    inputIdCard: function (t) {
      this.setData({
        idcard: t.detail.value
      });
    },
    inputPwd: function (t) {
      this.setData({
        password: t.detail.value
      });
    },
    loginEvent: function () {
      var t = this;
		if(this.idcard && a.isIdCardNo(this.idcard)||(r.test(this.idcard) || d.test(this.idcard))){
			if(this.password && this.password.length >=6){
				login({ username: this.idcard,password: this.password}).then((ret)=>{
					console.log(ret)
					if(ret.success){
						app.globalData.token = ret.data;
						if(ret.data){
							Vue.ls.set(ACCESS_TOKEN,ret.data)
						}
						loginInfoByShareToken({"token":app.globalData.token}).then((ret)=>{
								  console.log(ret)
								  if(ret.success){
									  uni.setStorageSync("userInfo",ret.data)
		
									  	app.globalData.zyzId = ret.data.id;
									  	app.globalData.loginFlag = 1;
									  	uni.switchTab({
									  	  url: "/pages/me/me"
									  	});
									  }
								  
						})
					} else {
						uni.showToast({
						  title: ret.message,
						  icon: "none"
						});
					}
				})
				
			}else{
				uni.showToast({
				  title: "请输入有效登录密码",
				  icon: "none"
				})
			}
		}else{
			uni.showToast({
			  title: "请输入有效手机号码或者身份证号",
			  icon: "none"
			})
		}
    
    },
    userLoginRequest: function () {
	  var a = {
	    data: {
	      api: n,
		  username: this.idcard,
		  password: this.password
	    }
	  };
	  return (0, t.request)(a, "normal", !0);
    },
  
    userBindRequest: function () {
      var e = {
        data: {
          api: i,
          openid: app.globalData.openId
        },
        token: app.globalData.token
      };
      return (0, t.request)(e, "common", !1);
    },
    makePhoneCall: function () {
      uni.makePhoneCall({
        phoneNumber: "4000035125"
      });
    },
    toReg: function () {
      uni.navigateTo({
        url: "/pages/entry/register"
      });
    },
    toPwd: function () {
      uni.navigateTo({
        url: "/pages/entry/password"
      });
    }
  }
};
</script>
<style>
.logo {
    width: 100%;
    height: auto;
    padding: 60rpx 0;
    border-bottom: 1rpx solid rgba(225,226,227,.75);
}

.logo image {
    display: block;
    width: 200rpx;
    height: 143rpx;
    margin: 0 auto;
}

.especial {
    padding: 40rpx 30rpx;
    text-align: right;
    font-size: 28rpx;
    color: #108ee9;
}

.btn {
    width: 690rpx;
    height: 88rpx;
    text-align: center;
    line-height: 88rpx;
    border-radius: 44rpx;
    font-size: 30rpx;
    margin: 0 auto 40rpx;
}
</style>